import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/channel/acRule/list',
  save='/channel/acRule/add',
  edit='/channel/acRule/edit',
  deleteOne = '/channel/acRule/delete',
  deleteBatch = '/channel/acRule/deleteBatch',
  importExcel = '/channel/acRule/importExcel',
  exportXls = '/channel/acRule/exportXls',

  ruleDevList='/channel/acRuleDev/list',
  deleteRuleDev='/channel/acRuleDev/delete',
  addRuleDev='channel/acRuleDev/addBatch',

  ruleList = '/channel/acRuleSection/list',
  addRule = '/channel/acRuleSection/add',
  editRule = '/channel/acRuleSection/edit',
  delRule = '/channel/acRuleSection/deleteBatch',

  channelList = '/channel/ssChannel/list',
  ruleChannelList = '/channel/acRuleChannel/queryRuleChannelList',
  deleteRuleChannel='/channel/acRuleChannel/delete',
  addRuleChannel='/channel/acRuleChannel/add',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 规则关联设备列表
 * @param params
 */
export const ruleDevList= (params) =>
  defHttp.get({url: Api.ruleDevList, params});
  
  
  /**
   * 规则关联设备删除单个
   */
  export const deleteRuleDev = (params,handleSuccess) => {
    return defHttp.delete({url: Api.deleteRuleDev, params}, {joinParamsToUrl: true}).then(() => {
      handleSuccess();
    });
  }
  
  /**
   * 添加已有设备
   */
  export const addselectDev = (params, handleSuccess) => {
    return defHttp.post({ url: Api.addRuleDev, params }).then(() => {
      handleSuccess();
    });
  };


export const ruleListApi = (params) => {
  let url =  Api.ruleList;
  return defHttp.get({url: url, params});
}

export const addRuleApi = (params) => {
  let url =  Api.addRule;
  return defHttp.post({url: url, params});
}

export const editRuleApi = (params) => {
  let url =  Api.editRule;
  return defHttp.post({url: url, params});
}
export const delRuleApi = (params) => {
  let url =  Api.delRule;
  return defHttp.post({url: url, params});
}

/**
 * 列表接口
 * @param params
 */
export const channelList = (params) =>
  defHttp.get({url: Api.channelList, params});

export const ruleChannelList = (params) =>
  defHttp.get({url: Api.ruleChannelList, params});  

/**
   * 规则关联通道删除单个
   */
export const deleteRuleChannel = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteRuleChannel, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 添加已有通道
 */
export const addRuleChannel = (params, handleSuccess) => {
  return defHttp.post({ url: Api.addRuleChannel, params }).then(() => {
    handleSuccess();
  });
};
